C     MUNILIST    Listing magnitude and time from FITS, MAT files
C     Copyright (C) 1997  Filip Hroch, Masaryk University, Brno, CZ
C                    
C     This program is free software; you can redistribute it and/or modify
C     it under the terms of the GNU General Public License as published by
C     the Free Software Foundation; either version 2 of the License, or
C     (at your option) any later version.
C     
C     This program is distributed in the hope that it will be useful,
C     but WITHOUT ANY WARRANTY; without even the implied warranty of
C     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
C     GNU General Public License for more details.
C
C     You should have received a copy of the GNU General Public License  
C     along with this program; if not, write to the Free Software
C     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
C
C    E-mail: hroch@physics.muni.cz
C    Web:    http://www.sci.muni.cz/~hroch/index.html
C    Postal address: F.Hroch
C                    Department of Theoretical Physics and Astrophysics
C                    Masaryk University
C                    Kotlarska 2
C                    611 37 Brno
C                    Czech Republic
C
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
C                                                                      C
C !!!!!!!!!!!!!!!!     This is DOS version   !!!!!!!!!!!!!!!!!!!!!!!!! C
C                                                                      C
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
C For Microsoft Powerstation compiler

      INCLUDE 'FLIB.FI'
      INCLUDE 'FLIB.FD'

C      PROGRAM MUNILIST

      CHARACTER*80 NAMFITS,NAMDIR,LINE
      INTEGER I,J,L,COLUMN,NSTARS,STARS(1000),ICIT,MUNILIST,LN,OUTLST
      INTEGER*2 S
      LOGICAL STDINP

      DATA STDINP/.FALSE./,COLUMN/4/
      DATA ICIT/1/,NAMFITS/' '/,NAMDIR/' '/,NSTARS/0/,OUTLST/0/
      
      DO I = 1,NARGS()-1
        CALL GETARG(INT2(I),LINE,S)
C dir file
        J = INDEX(LINE,'@')
        IF( J.NE.0 )THEN
          NAMDIR = LINE(J+1:)
          IF( NAMDIR.EQ.' ' ) STDINP = .TRUE.
        ENDIF
C Column        
        J = INDEX(LINE,'col=')
        IF( J.NE.0 )THEN 
          READ(LINE(J+4:),'(I5)',IOSTAT=J) L
          IF( J.EQ.0 ) COLUMN = L
        ENDIF
C Star 
        READ(LINE,'(I5)',IOSTAT=J) L
        IF( J.EQ.0 ) THEN
          NSTARS = NSTARS + 1
          STARS(NSTARS) = L
        ENDIF
C output list
        IF( LINE.EQ.'-of' ) OUTLST = 1
      ENDDO
      
C input from file
      IF( NAMDIR.NE.' ' )THEN
        OPEN(10,FILE=NAMDIR,STATUS='OLD',IOSTAT=I)
        IF( I.NE.0 ) STOP 'Can''t open file with name(s) of image(s).'
10      READ(10,'(A)',END=20) NAMFITS
        IF( NAMFITS.EQ.' ' ) GOTO 10
        IF( MUNILIST(NAMFITS,COLUMN,NSTARS,STARS,OUTLST) .NE. 0)
     *    WRITE(*,*) 'Can''t read the data file: ',NAMFITS(:LN(NAMFITS))
        ICIT = ICIT + 1
        GOTO 10
20      CLOSE(10)
      ENDIF

C image names from command line
      DO I = 1, NARGS()-1
        CALL GETARG(INT2(I),NAMFITS,S)
        READ(NAMFITS,'(I5)',IOSTAT=J) L
        IF( INDEX(NAMFITS,'=').EQ.0 .AND. INDEX(NAMFITS,'@').EQ.0 .AND. 
     .      J.NE.0 .AND. INDEX(NAMFITS,'-').EQ.0 )THEN
          IF( MUNILIST(NAMFITS,COLUMN,NSTARS,STARS,OUTLST) .NE. 0)
     *    WRITE(*,*) 'Can''t read the data file: ',NAMFITS(:LN(NAMFITS))
          ICIT = ICIT+1
        ENDIF
      ENDDO

C images names from standart input
      IF( STDINP )THEN
40      READ(*,'(A)',END=50) NAMFITS
        IF( MUNILIST(NAMFITS,COLUMN,NSTARS,STARS,OUTLST) .NE. 0)
     *    WRITE(*,*) 'Can''t read the data file: ',NAMFITS(:LN(NAMFITS))
          ICIT = ICIT+1
        GOTO 40
50      CONTINUE
      ENDIF

      IF( NARGS().GT.1 .AND. ICIT.EQ.1 )
     .  PRINT *,'No input files.'

      IF( NARGS().EQ.1 .AND. ICIT.EQ.1 )THEN
        WRITE(*,*) 'MUNILIST Version 1.0, Copyright (C) 1997 F.Hroch,',
     *        'Masaryk University, Brno, CZ'
        WRITE(*,*) 'Munilist comes with ABSOLUTELY NO WARRANTY;',
     *        'This is free software, and you are'
        WRITE(*,*) 'welcome to redistribute under certain conditions;',
     *        'see "gnulic.doc" for details.'
        PRINT *
        PRINT *,'MUNILIST   Listing magnitude and time from FITS, MAT '
     .          ,'files.'
        PRINT *
        PRINT *,'Usage:munilist [@dirfile] [-of] [col=column] ',
     .          '[line_var] [line_comp1] ..' 
        PRINT *,'               [image1] ..'
        PRINT *
        PRINT *,'@dirfile= file with name(s) of image(s) for output list
     *, no wildcards *,?'
        PRINT *,'           (for only "@", read image(s) name(s) from st
     *andart input)'
        PRINT *,'column= column for listing (4 = Aperture 1, default)'
        PRINT *,'-of= full output list (default short output list)'
        PRINT *,'line_var, line_comp1...= line with stars'
        PRINT *,'image1...= name(s) of simple image(s)'
        PRINT *
      ENDIF

      END

CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC

